import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { EmployeeOrganizationRole } from '../domain/employee-organization-role';
import { Employee, EmployeeOrganizationLevel, EmployeeRelation } from '../domain/sparrow';

@Injectable({
  providedIn: 'root'
})
export class EmployeeService {


  host:string = "http://localhost:8091/api";

  constructor(private httpClient: HttpClient) { }


  public getParents(employeeId: any) {
    return this.httpClient.get<any[]>(this.host+"/employees/getParents",{ params:{employeeId:employeeId}})
  }

  public getLevels(employeeId: string) {
    return this.httpClient.get<any[]>(this.host+"/employees/getLevels",{ params:{employeeId:employeeId}})
  }

  public getRoles(employeeId: string) {
    return this.httpClient.get<any[]>(this.host+"/employees/getRoles",{ params:{employeeId:employeeId}})
  }

  public getTreeByParentId(parentId: string){
    return this.httpClient.get<any>(this.host+"/employees/getTreeByParentId",{ params:{parentId:parentId}})
  }

  public saveBatch(employees: Employee[]){
    return this.httpClient.post(this.host+"/employees/batch",employees);
  }

  public save(employee: Employee){
    return this.httpClient.post<Employee>(this.host+"/employees",employee);
  }

  public saveMasterOrganization(employeeId:string, organizationId: string){
    return this.httpClient.put<any>(this.host+"/employees",{},{params:{employeeId: employeeId, organizationId: organizationId}});
  }

  public saveRole(empRoles:EmployeeOrganizationRole[]){
    return this.httpClient.post<Employee>(this.host+"/employees/roles/batch",empRoles);
  }

  public saveLevel(empRoles:EmployeeOrganizationLevel[]){
    return this.httpClient.post<Employee>(this.host+"/employees/levels/batch",empRoles);
  }

  public saveRelations(employeeRelations: EmployeeRelation[]){
    return this.httpClient.post(this.host+"/employees/relations/batch",employeeRelations);
  }

  public getModelName(){
    return this.httpClient.get<any>(this.host+"/employees/getModelName");
  }

  deleteBatch(ids$: any) {
    return this.httpClient.delete(this.host+"/employees/batch",{body:ids$});
  }
}
